<template>
  <!-- 文章点赞组件 -->
  <van-icon :color="isliking === 1 ? 'red': '#777'" name="good-job-o" @click="onliking" />
</template>

<script>
import { addArticleLiking, deleteArticleLiking } from '@/api/article.js'
export default {
  data () {
    return {}
  },
  props: {
    isliking: {
      type: Number,
      require: true
    },
    articleId: {
      type: [Number, String],
      require: true
    }
  },
  model: {
    prop: 'isliking'
  },
  methods: {
    async onliking () {
      try {
        if (this.isliking === 1) {
          // 取消点赞
          await deleteArticleLiking(this.articleId)
          this.$emit('input', -1)
          this.$toast('取消点赞成功')
        } else {
          // 点赞
          await addArticleLiking(this.articleId)
          this.$emit('input', 1)
          this.$toast('点赞成功')
        }
      } catch (err) {
        this.$toast('操作失败')
      }
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
